﻿using System;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace SBPweb.PROvibe.Server.Framework.Actors.Communication
{

    [Serializable]
    [DataContract]
    public abstract class MessageContentBase
    {

        //private static LockHelper lh = new LockHelper("MessageContentBase");
        private static object lh = new object();
        private static List<Type> types;

        //[DataMember(IsRequired = false, EmitDefaultValue = false)]
        public static IEnumerable<Type> DataContactTypes
        {
            get
            {
                //using (lh.GetLock())
                lock (lh)
                {
                    if (types == null)
                    {
                        types = new List<Type>();
                        foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
                        {
                            object[] o = type.GetCustomAttributes(typeof(DataContractAttribute), true);
                            if (o != null && o.Length > 0)
                            {
                                types.Add(type);
                            }
                        }
                    }
                    return types;
                }
            }
        }

    }

}